package cn.itcast.bos.service.transit.impl;

import cn.itcast.bos.dao.transit.InOutStorageInfoRepository;
import cn.itcast.bos.dao.transit.TransitInfoRepository;
import cn.itcast.bos.domain.transit.InOutStorageInfo;
import cn.itcast.bos.domain.transit.TransitInfo;
import cn.itcast.bos.service.transit.InOutStorageInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class InOutStorageInfoServiceImpl implements InOutStorageInfoService {
    @Autowired
    private InOutStorageInfoRepository inOutStorageInfoRepository;
    @Autowired
    private TransitInfoRepository transitInfoRepository;

    @Override
    public void save(InOutStorageInfo model, String inOutStoreId) {
        TransitInfo transitInfo = transitInfoRepository.findOne(Integer.parseInt(inOutStoreId));
        transitInfo.getInOutStorageInfos().add(model);
        if("到达网点".equals(model.getOperation())){
            transitInfo.setStatus("到达网点");
            transitInfo.setOutletAddress(model.getAddress());
        }
        inOutStorageInfoRepository.save(model);
        transitInfoRepository.save(transitInfo);
    }
}
